#!/bin/zsh
#
# Copyright 2009 Google Inc. All Rights Reserved.
# Author: arb@google.com (Anthony Baxter)

cd $1/tiles
for i in */*(/)
do
  mkdir -p ../q/$i ../opt/$i
  for j in $i/*(.)
  do
    pngnq -f -e '.png' -n 256 -d ../q/$i $j
    pngcrush -q -d ../opt/$i ../q/$i/*
  done
done

cd ../opt

echo "step 1 `pwd`"
for i in *(/)
do
  echo "step 2 `pwd`"
  cd $i
  echo "step 3 `pwd`"
  for j in *(/)
  do
    echo "from `pwd`, zipping $j"
    zip -9rq $j.zip $j
  done
  cd ..
done

for i in */*.zip
do
  mv `pwd`/$i `pwd`/../../../web/zips/tiles/nasa/$i
done

